package br.ufmg.dcc.vod.remoteworkers.sync;

import java.rmi.RemoteException;

import br.ufmg.dcc.vod.remoteworkers.Command;
import br.ufmg.dcc.vod.remoteworkers.util.SyncQueueBasedLock;

class SyncCommandProcessorWLock implements SyncCommandProcessor {

	private final SyncQueueBasedLock lock;
	private final SyncCommandProcessor processor;

	public SyncCommandProcessorWLock(SyncCommandProcessor processor, SyncQueueBasedLock lock)	throws RemoteException {
		this.processor = processor;
		this.lock = lock;
	}

	@Override
	public <T, I> T process(Command<T, I> command) throws RemoteException, Exception {
		try {
			T process = processor.process(command);
			return process;
		} finally {
			lock.lock();
		}
	}	
}